home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / DataScope 2.0.3 / DataScope2l / DSSource / f2view.c next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  36.3 KB  |  201 lines  |  [TEXT/MPS ]

  1. # include <types.h>                 /* Nearly always required */
  2. # include <quickdraw.h>             /* To access the qd globals */
  3. # include <toolutils.h>             /* CursHandle and iBeamCursor */
  4. # include <fonts.h>                 /* Only for InitFonts() trap */
  5. # include <events.h>                /* GetNextEvent(), ... */
  6. # include <windows.h>                /* GetNewWindow(), ... */
  7. # include <controls.h>
  8. # include <files.h>
  9. # include <fcntl.h>
  10. # include <packages.h>
  11. # include <dialogs.h>                /* InitDialogs() and GetNewDialog() */
  12. # include <menus.h>                 /* EnableItem(), DisableItem() */
  13. # include <desk.h>                    /* SystemTask(), SystemClick() */
  14. # include <textedit.h>                /* TENew() */
  15. # include <scrap.h>                 /* ZeroScrap() */
  16. # include <StdIO.h>
  17. # include <Math.h>
  18. # include <Palette.h>
  19.  
  20. # include "fview.h"
  21.  
  22. #include    <Resources.h>
  23. /*
  24.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25.     
  26.     findbi     find the FTEXT data structure associated with another 
  27.                 data structure of a different type.
  28.     
  29.  */
  30.  
  31.  struct Mwin * findbi (tw)
  32.      struct Mwin    *tw;
  33. {
  34.     struct Mwin *mw;
  35.     extern struct Mwin    *Mlist;
  36.     
  37.     mw = Mlist;
  38.     while (mw)
  39.         if (mw->wintype == FBI && mw->dat == tw->dat)
  40.             return (mw);
  41.         else
  42.             mw = mw->next;
  43.             
  44.     return NULL;
  45. }
  46.  
  47. /*
  48.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49.     
  50.     findimage     find the FTEXT data structure associated with another 
  51.                 data structure of a different type.
  52.     
  53.  */
  54.  
  55.  struct Mwin * findimage (tw)
  56.      struct Mwin    *tw;
  57. {
  58.     struct Mwin *mw;
  59.     extern struct Mwin    *Mlist;
  60.     
  61.     mw = Mlist;
  62.     while (mw)
  63.         if (mw->wintype == FIMG && mw->dat == tw->dat)
  64.             return (mw);
  65.         else
  66.             mw = mw->next;
  67.             
  68.     return NULL;
  69. }
  70.  
  71. /*
  72.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73.     
  74.     finddata     find the FTEXT data structure associated with another 
  75.                 data structure of a different type.
  76.     
  77.  */
  78.  
  79.  struct Mwin * finddata (tw)
  80.      struct Mwin    *tw;
  81. {
  82.     struct Mwin *mw;
  83.     extern struct Mwin    *Mlist;
  84.     
  85.     mw = Mlist;
  86.     while (mw)
  87.         if (mw->wintype == FTEXT && mw->dat == tw->dat)
  88.             return (mw);
  89.         else
  90.             mw = mw->next;
  91.             
  92.     return NULL;
  93. }
  94.  
  95. /*
  96.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97.     interpit    create an interpolated image from the dataset.
  98.                     
  99.                 tw = pointer to the Mwin structure
  100.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101. */
  102. interpit(tw)
  103.     struct    Mwin        *tw;
  104. {
  105.     struct    fdatawin    *td;
  106.     register int        i,change;
  107.     struct    Mwin        *tempw, *keepw;
  108.     register float        *f;
  109.     void                ErrorAlert();
  110.     
  111.     if (!tw->dat)        return;
  112.     keepw = tw;
  113.     td = tw->dat;
  114.     
  115.     /* is there already an interpolation record. */
  116.     
  117.     if (td->interp) {
  118.     
  119.         /* did the interpolation size change. */
  120.         
  121.         tempw = findbi (tw);
  122.         if (td->xsize != tempw->bw->xsize || td->ysize != tempw->bw->ysize)
  123.             {
  124.             if (td->interp == tw)
  125.                 keepw = tw = finddata (tw);
  126.                 
  127.             loseinterp (td->interp);
  128.             td = tw->dat;
  129.             }
  130.         else {
  131.             tw = td->interp;
  132.             setwtitle(tw->win,td->dvar);    /* could be a new window title */
  133.             interpdraw(tw);
  134.             SetCursor(&qd.arrow);
  135.             return;
  136.         }
  137.     }
  138.  
  139.     if (td->xsize < 50)    {        /* minimum sizes for window to create */
  140.         td->xsize = 50;
  141.         td->exx = 50/td->xdim;
  142.     }
  143.     if (td->ysize < 50) {
  144.         td->ysize = 50;
  145.         td->exy = 50/td->ydim;
  146.     }
  147.     
  148.     if (td->xsize & 1)            /* Odd width window.  For interpolated image, 
  149.                                     we don't need odd width windows, who'll notice? */
  150.         td->xsize++;
  151. /*
  152. *  warning about continuous scales.  Must be increasing or decreasing.
  153. */
  154.     change = 0;                                            /* flag == OK */
  155.     f = td->xvals;
  156.     if (*td->xvals > *(td->xvals + td->xdim -1) ) {        /* decreasing */
  157.         for (i=0; i < td->xdim-1; i++,f++)
  158.             if (*f < *(f+1))
  159.                 change = 1;
  160.     }
  161.     else {                                                /* increasing */
  162.         for (i=0; i < td->xdim-1; i++,f++)
  163.             if (*f > *(f+1))
  164.                 change = 1;
  165.     }
  166.     f = td->yvals;
  167.     if (*td->yvals > *(td->yvals + td->ydim -1) ) {        /* decreasing */
  168.         for (i=0; i < td->ydim-1; i++,f++)
  169.             if (*f < *(f+1))
  170.                 change = 1;
  171.     }
  172.     else {                                                /* increasing */
  173.         for (i=0; i < td->ydim-1; i++,f++)
  174.             if (*f > *(f+1))
  175.                 change = 1;
  176.     }
  177.     
  178.     if (change)
  179.         NoteAlert(1006,nil);                            /* not OK, warn user */
  180.  
  181. /*
  182. *  Are we going to have enough memory to do this?
  183. */
  184.     if (checkmem(td->xsize*td->ysize+2000))
  185.        {ErrorAlert(GetResource('STR ',1001));
  186.         return;
  187.        }
  188.  
  189.     tempw = (struct Mwin *)NewPtr(sizeof(struct Mwin));
  190.     if (!tempw)
  191.        {ErrorAlert(GetResource('STR ',1001));
  192.         return;
  193.        }
  194.         
  195.     tempw->dat = tw->dat;            /* point to same dataset */
  196.     tempw->dat->refcount++;            /* increase refcount bookkeeping */
  197.     tempw->bw = (struct fbiwin *)NewPtr(sizeof(struct fbiwin));
  198.     
  199.     tw = tempw;                        /* move to this element of list */
  200.     
  201.     tw->dat->interp = tw;            /* back pointer for